window.onload=function () {
	getallcar();
}

function getwaitcheck() {
	$.ajax({
		url: 'http://172.18.21.150/ToGo/getCarByStatus',
		type: 'post',
		dataType: 'json',
		data:{status:'0',pageNum:1,pageSize:10},
		success:function (result) {

			var d=result.data;
			if (result.status=='200') {
				$("table").html('tr><th>品牌</th><th>车系</th><th>拥有者</th><th>价格</th><th>图片</th><th>状态</th><th>操作</th></tr>');

				for(i=0;i<d.length;i++){
				var status;
          	 if(d[i].status=='0'){
           		status='待审核';
         	  }else if(d[i].status=='1'){
           		status='在售';
         	  }else{
         	  	status='已售';
         	  }
					$("table").append('');
						$("table").append('<tr class="pertr"><td>'+d[i].brand+'</td><td>'+d[i].model+'</td><td>'+d[i].owner_name+'</td><td>'+d[i].price+'</td><td><img src="http://172.18.21.150/'+d[i].photo+'" alt="" width="100px" height="100px"/></td><td>'+status+'</td><td><a href="javascript:void(0)" onclick="passcheck('+d[i].car_id+')">通过</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="deletecar('+d[i].car_id+')">删除</a></td></tr>');
				}
			}
		},
		error:function(){
			alert('error');
		}
	});
	
}

function getallcar() {
	$.ajax({
		url: 'http://172.18.21.150/ToGo/listAllCar',
		type: 'post',
		dataType: 'json',
		data:{pageNum:1,pageSize:10},
		success:function (result) {

			var d=result.data;
			if (result.status=='200') {
				$("table").html('tr><th>品牌</th><th>车系</th><th>拥有者</th><th>价格</th><th>图片</th><th>状态</th><th>操作</th></tr>');

				for(i=0;i<d.length;i++){
				var status;
          	 if(d[i].status=='0'){
           		status='待审核';
           		$("table").append('<tr class="pertr"><td>'+d[i].brand+'</td><td>'+d[i].model+'</td><td>'+d[i].owner_name+'</td><td>'+d[i].price+'</td><td><img src="http://172.18.21.150/'+d[i].photo+'" alt="" width="100px" height="100px"/></td><td>'+status+'</td><td><a href="javascript:void(0)" onclick="passcheck('+d[i].car_id+')">通过</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="deletecar('+d[i].car_id+')">删除</a></td></tr>');
         	  }else if(d[i].status=='1'){
           		status='在售';
           		$("table").append('<tr class="pertr"><td>'+d[i].brand+'</td><td>'+d[i].model+'</td><td>'+d[i].owner_name+'</td><td>'+d[i].price+'</td><td><img src="http://172.18.21.150/'+d[i].photo+'" alt="" width="100px" height="100px"/></td><td>'+status+'</td><td><a href="javascript:void(0)" onclick="deletecar('+d[i].car_id+')">删除</a></td></tr>');
         	  }else{
         	  	status='已售';
         	  	$("table").append('<tr class="pertr"><td>'+d[i].brand+'</td><td>'+d[i].model+'</td><td>'+d[i].owner_name+'</td><td>'+d[i].price+'</td><td><img src="http://172.18.21.150/'+d[i].photo+'" alt="" width="100px" height="100px"/></td><td>'+status+'</td><td><a href="javascript:void(0)" onclick="deletecar('+d[i].car_id+')">删除</a></td></tr>');
         	  }

						
				}
			}
		},
		error:function(){
			alert('error');
		}
	});
	
}

function getsold() {
	$.ajax({
		url: 'http://172.18.21.150/ToGo/getCarByStatus',
		type: 'post',
		dataType: 'json',
		data:{status:'2',pageNum:1,pageSize:10},
		success:function (result) {

			var d=result.data;
			if (result.status=='200') {
				$("table").html('tr><th>品牌</th><th>车系</th><th>拥有者</th><th>价格</th><th>图片</th><th>状态</th><th>操作</th></tr>');

				for(i=0;i<d.length;i++){
				var status;
          	 if(d[i].status=='0'){
           		status='待审核';
         	  }else if(d[i].status=='1'){
           		status='在售';

         	  }else{
         	  	status='已售';
         	  }
						$("table").append('<tr class="pertr"><td>'+d[i].brand+'</td><td>'+d[i].model+'</td><td>'+d[i].owner_name+'</td><td>'+d[i].price+'</td><td><img src="http://172.18.21.150/'+d[i].photo+'" alt="" width="100px" height="100px"/></td><td>'+status+'</td><td><a href="javascript:void(0)" onclick="deletecar('+d[i].car_id+')">删除</a></td></tr>');
				}
			}
		},
		error:function(){
			alert('error');
		}
	});
	
}

function getselling() {
	$.ajax({
		url: 'http://172.18.21.150/ToGo/getCarByStatus',
		type: 'post',
		dataType: 'json',
		data:{status:'1',pageNum:1,pageSize:10},
		success:function (result) {

			var d=result.data;
			if (result.status=='200') {
				$("table").html('tr><th>品牌</th><th>车系</th><th>拥有者</th><th>价格</th><th>图片</th><th>状态</th><th>操作</th></tr>');

				for(i=0;i<d.length;i++){
				var status;
          	 if(d[i].status=='0'){
           		status='待审核';
         	  }else if(d[i].status=='1'){
           		status='在售';
         	  }else{
         	  	status='已售';
         	  }
						$("table").append('<tr class="pertr"><td>'+d[i].brand+'</td><td>'+d[i].model+'</td><td>'+d[i].owner_name+'</td><td>'+d[i].price+'</td><td><img src="http://172.18.21.150/'+d[i].photo+'" alt="" width="100px" height="100px"/></td><td>'+status+'</td><td><a href="javascript:void(0)" onclick="deletecar('+d[i].car_id+')">删除</a></td></tr>');
				}
			}
		},
		error:function(){
			alert('error');
		}
	});
	
}




function passcheck(car_id) {
	$.ajax({
		url: 'http://172.18.21.150/ToGo/auditCar',
		type: 'post',
		dataType: 'json',
		data:{car_id:car_id,status:'1'},
		success:function (result) {
			if (result.status=='200') {
				window.location.reload(true);
			}
		},
		error:function(){
			alert('error');
		}
	});
}

function deletecar(car_id) {
	$.ajax({
		url: 'http://172.18.21.150/ToGo/deleteCar',
		type: 'post',
		dataType: 'json',
		data:{id:car_id},
		success:function (result) {
			if (result.status=='200') {
				window.location.reload(true);
			}
		},
		error:function(){
			alert('error');
		}
	});
}